package com.jkc.xh.adapters.viewholder;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jkc.xh.R;
import com.jkc.xh.models.BalModel;
import com.jkc.xh.utils.Tool;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by wangjie28 on 2015/11/13.
 */
@EViewGroup(R.layout.item_bal)
public class BalItemView extends RelativeLayout {


    @ViewById(R.id.stock_name)
    TextView stock_name;

    @ViewById(R.id.stock_code)
    TextView stock_code;

    @ViewById(R.id.sell_amount)
    TextView sell_amount;

    @ViewById(R.id.all_realin)
    TextView all_realin;

    @ViewById(R.id.buss_time)
    TextView buss_time;

    @ViewById(R.id.close_time)
    TextView close_time;

    public BalItemView(Context context) {
        super(context);
    }

    public BalItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public void bind(BalModel model) {
        stock_name.setText(model.stock_name);
        stock_code.setText(model.stock_code);
        sell_amount.setText(model.sell_amount);
        all_realin.setText(model.all_realin);
        buss_time.setText(Tool.formatSecondSimpleFullDate(model.buss_time));
        close_time.setText(Tool.formatSecondSimpleFullDate(model.close_time));
        if (model.isProfit()) {
            setAllTextColor(getResources().getColor(R.color.text_color_red));
        } else {
            setAllTextColor(getResources().getColor(R.color.text_color_blue));
        }
    }


    private void setAllTextColor(int textColorId) {
        stock_name.setTextColor(textColorId);
        stock_code.setTextColor(textColorId);
        sell_amount.setTextColor(textColorId);
        all_realin.setTextColor(textColorId);
        buss_time.setTextColor(textColorId);
        close_time.setTextColor(textColorId);
    }
}
